package Tests;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import ModelLayer.CustomerRecords;
import ModelLayer.GroupRecords;
import ModelLayer.Group;
import ModelLayer.RealException;

public class CustomerTest {

	private CustomerRecords customerRecords = CustomerRecords.getInstance();
	private GroupRecords groupRecords = GroupRecords.getInstance();
	

	@Before
	public void setUp() throws Exception {
		groupRecords.createGroup(1, 0.1, 0.1, 0.1);
		groupRecords.createGroup(2, 0.2, 0.2, 0.2);
		customerRecords.addCustomer("Madalin", "Hobrovej", 555, 1);
	}

	@Test
	public void testUpdateName() throws RealException {
		customerRecords.getCustomer(1).setName("Test");
		Assert.assertEquals("Test", customerRecords.getCustomer(1).getName());
	}
	
	@Test
	public void testUpdateAddress() throws RealException {
		customerRecords.getCustomer(1).setAddress("Test");
		Assert.assertEquals("Test", customerRecords.getCustomer(1).getAddress());
	}
	
	@Test
	public void testUpdatePhone() throws RealException {
		customerRecords.getCustomer(1).setPhone(777);
		Assert.assertEquals(777, customerRecords.getCustomer(1).getPhone());
	}
	
	@Test
	public void testUpdateGroup() throws RealException {
		Group group2 = groupRecords.getGroup(2);
		customerRecords.getCustomer(1).setGroup(group2);
		Assert.assertEquals(group2, customerRecords.getCustomer(1).getGroup());
	}

	
	@Test
	public void testDelete() throws RealException {
		customerRecords.removeCustomer(1);
		boolean found = true;
		try
		{
			customerRecords.getCustomer(1);
		}
		catch (RealException e) 
		{
			found = false;
		}
		Assert.assertFalse(found);		
	}
	
	@Test
	public void testGet() throws RealException {
		Assert.assertNotSame(null, customerRecords.getCustomer(1));
	}
}
